﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ChoViet.Lib.Paging;
using System.Linq.Dynamic;

namespace ChoViet.Model
{
    public class MailManager
    {
        /*
        public static List<MailCategory> GetChildCategory(int catid)
        {
            try
            {
                var db = new ChoVietDataContext();
                var returnVal = new List<MailCategory>();
                var curentCat = db.MailCategories.Single(o => o.ID == catid);
                returnVal.Add(curentCat);

                foreach (var item in curentCat.MailCategories)
                {
                    returnVal.AddRange(GetChildCategory(item.ID));
                }

                return returnVal;
            }
            catch (Exception exp)
            {
                return null;
            }
        }
        public static List<MailCategory> GetListCategory()
        {
            try
            {
                var db = new ChoVietDataContext();
                var returnVal = new List<MailCategory>();
                var listParent = db.MailCategories.Where(e => e.ParentID == null).OrderBy(string.Format("{0} {1}", "ID", "asc")).ToList();
                foreach (var item in listParent)
                {
                    var l = GetChildCategory(item.ID);
                    returnVal.AddRange(l);
                }

                return returnVal;
            }
            catch (Exception exp)
            {
                return null;
            }
        }
        public static List<int> GetChild(int catid)
        {
            try
            {
                var db = new ChoVietDataContext();
                var returnVal = new List<int>();
                var curentCat = db.MailCategories.Single(o => o.ID == catid);
                returnVal.Add(curentCat.ID);

                foreach (var item in curentCat.MailCategories)
                {
                    returnVal.AddRange(GetChild(item.ID));
                }

                return returnVal;
            }
            catch (Exception exp)
            {
                return null;
            }
        }
        */
    }
}
